package com.bobo.mm.dogs;

/**
 * 心跳看门狗管理器
 * Created by cocolove2 on 2020/6/18.
 */
public class DogManager {
    /**
     * 心跳计数器
     */
    private DogFather mDog;

    private DogManager() {
    }

    private static class DogManagerHolder {
        private static final DogManager INSTANCE = new DogManager();
    }

    public static DogManager getInstance() {
        return DogManagerHolder.INSTANCE;
    }


    public DogFather getDog() {
        return mDog;
    }

    public DogManager setDog(DogFather dog) {
        mDog = dog;
        return this;
    }

    private void checkDogNull() {
        if (mDog == null) {
            throw new IllegalArgumentException("请给狗管理一条狗啊！");
        }
    }

    /**
     * 喂狗
     */
    public void feedDog() {
        checkDogNull();
        mDog.happy();
    }

    /**
     * 放狗
     */
    public void lookup() {
        checkDogNull();
        mDog.doForaging();
    }

    /**
     * 搜狗回家
     */
    public void goHome() {
        checkDogNull();
        mDog.goHome();
    }


    public void setDogListener(DogFather.DogListener listener) {
        checkDogNull();
        mDog.setDogListener(listener);
    }
}
